import { getByPid, getByIdMoreDetail,
   queryForList, createOrUpdate,
    deleteData, handleRoleMenu,
     getByRoleId } from '@/api/system/menuApi'

const state = {
}

const mutations = {
}

const actions = {
  getByPid({ commit }, pid) {
    return new Promise((resolve, reject) => {
      getByPid(pid).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  getByRoleId({ commit }, roleId) {
    return new Promise((resolve, reject) => {
      getByRoleId(roleId).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  getByIdMoreDetail({ commit }, dataId) {
    return new Promise((resolve, reject) => {
      getByIdMoreDetail(dataId).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  queryForList({ commit }, params) {
    return new Promise((resolve, reject) => {
      queryForList(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  createOrUpdate({ commit }, params) {
    return new Promise((resolve, reject) => {
      createOrUpdate(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  handleRoleMenu({ commit }, params) {
    return new Promise((resolve, reject) => {
      handleRoleMenu(params).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  deleteData({ commit }, dataId) {
    return new Promise((resolve, reject) => {
      deleteData(dataId).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

